<?php 
session_start();
class Add_maker extends CI_Controller{
    public function __construct() {
    parent::__construct();
    $this->load->model('Account_m');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('session');
    }
    public function index()
    {        
        $password=$this->input->post('password');
        $name=$this->input->post('name');
        $id_mk=$this->input->post('id');
        $email=$this->input->post('email');
        $adress=$this->input->post('adress');
        $phone=$this->input->post('phone');
        $session_data_sm = $this->session->userdata('logged_in_mg');
	$data['id_mg'] = $session_data_sm['id_mg'];
        //echo $name;
        if($this->check_space($id_mk,$password)==1)
        {
            if( $this->Account_m->add_account_mk($id_mk,$data['id_mg'],'maker')==0)
             {   
                    echo "<script type='text/javascript'>";	
                    echo "alert ('その出題者は存在した');";
                    echo "</script>";
                    redirect('manager/add_maker','refresh');           
                }
            else {
                    $this->Account_m->inser_database_mk($id_mk,$password,$email,$adress,$data['id_mg'],$phone,$name,'maker');
                    echo "<script type='text/javascript'>";	
                    echo "alert ('出題者の作成が成功!!! ');";
                    echo "</script>";
                    redirect('manager','refresh'); 
                    }
        }  
        else {redirect('manager/add_maker','refresh');     }
        }
        public function check_space($a,$b){
        if($a!=NULL && $b!=NULL)
        {
            return 1;
        }
        else
            return 0;
        }
    }
?>
